﻿namespace slava.dao
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DAO;

    public class AcceptanceProductRepository : IDao<Acceptance_Product>
    {
        skladEntities sklad;

        public AcceptanceProductRepository()
        {
            this.sklad = new skladEntities();
        }

        public IEnumerable<Acceptance_Product> GetAll()
        {
            return sklad.Acceptance_Product;
        }

        public void Edit(Acceptance_Product entity)
        {
            var temp = sklad.Acceptance_Product.Single(x => x.Id == entity.Id);
            sklad.Entry(temp).CurrentValues.SetValues(entity);
            sklad.SaveChanges();
        }

        public void Add(Acceptance_Product entity)
        {
            sklad.Acceptance_Product.Add(entity);
            sklad.SaveChanges();
        }

        public void Delete(int id)
        {
            var entity = sklad.Acceptance_Product.FirstOrDefault(t => t.Id == id);
            sklad.Acceptance_Product.Remove(entity);
            sklad.SaveChanges();
        }

        public Acceptance_Product GetById(int id)
        {
            return sklad.Acceptance_Product.FirstOrDefault(t => t.Id == id);
        }
    }
}
